#include "player.h"

#include "qdebug.h"

player::player(int type) : buff(20, 0) {
  // 初始化各种属性
  maxHp = 30;
  Hp = 30;
  maxMp = 3;
  Mp = 3;
  extraPower = 0;
  shield = 0;
  keepShield = 0;
  exp = 0;
  level = 1;
  isAct = 1;
  // qDebug()<<"inticard"<<cardNumber;
  cardNumber = 5;  // 初始5张
  drawNumber = 5;  // 每回合5张
  money = 10;
  killNum = 0;

  switch (type) {
    case 1:
      playerName = "WarriorCards";
      break;

    case 2:
      playerName = "AssassinsCards";
      break;

    case 3:
      playerName = "WarriorCards";
      break;

    case 4:
      playerName = "WarriorCards";
      break;

    default:
      break;
  }

  manager = new CardManager(type);
}

int player::getHp() { return Hp; }

int player::getMp() { return Mp; }

int player::getExtraPower() { return extraPower; }

int player::getShield() { return shield; }

int player::getExp() { return exp; }

int player::getLevel() { return level; }

int player::getIsAct() { return isAct; }

int player::getMoney() { return money; }

int player::getMaxHp() { return maxHp; }

int player::getMaxMp() { return maxMp; }

void player::addMaxHp(int a) {
  maxHp += a;

  if (maxHp < 1) {
    maxHp = 1;
  }

  // 刷新hp
  setHp(0);
}

void player::addMaxMp(int a) {
  maxMp += a;

  if (maxMp < 0) {
    maxMp = 0;
  }
}

void player::addMoney(int a) {
  money += a;

  if (money < 0) {
    money = 0;
  }
}

void player::setHp(int a) {
  Hp += a;

  if (Hp < 0) Hp = 0;

  if (Hp > maxHp) Hp = maxHp;
}

void player::setMp(int a) {
  Mp += a;

  if (Mp < 0) Mp = 0;
}

void player::addExtraPower(int a) {
  extraPower += a;

  if (extraPower < 0) extraPower = 0;
}

void player::setShield(int a) {
  shield += a;

  if (shield < 0) shield = 0;
}

void player::setExp(int a) {
  exp += a;

  if (Mp < 0) Mp = 0;
}

void player::setLevel(int a) {
  level += a;

  if (level < 0) level = 0;
}

void player::setIsAct(int a) {
  if ((a == 1) || (a == 0)) {
    isAct = a;
  }
}

int player::getHBD() { return HpBeforeDefeat; }

void player::setHpBeforeDefeat(int value) { HpBeforeDefeat = value; }
void player::getSpeShiheld(int a) {
  keepShield += a;
  shield += a;
}
void player::calcuShield() {
  shield = min(shield, keepShield);
  keepShield = 0;
}
void player::clearbuff() {
  for (int i = 0; i < 20; i++) {
    buff[i] = 0;
  }
}
void player::addbuff(int a, int b) { buff[a] += b; }
int player::getbuff(int a) { return buff[a]; }
